package com.game.modular.game.battle.process.skillEffectHandle.impl;

import com.game.modular.game.battle.process.skillEffectHandle.base.BaseSkillEffectStrategy;
import com.game.modular.game.battle.panel.attribute.domain.PlayerHeroAttribute;
import com.game.modular.game.battle.panel.skillEffect.PvpSkillEffect;
import org.springframework.stereotype.Component;


public class DotStrategy {
    @Component
    public static class BaseDotStrategy extends BaseSkillEffectStrategy {
        @Override
        public PvpSkillEffect applyEffect(PvpSkillEffect pvpSkillEffect) {
            String Z = pvpSkillEffect.getSkillEffectLayer().getName();
            return pvpSkillEffect;
        }

        public void physicsApply(
                PvpSkillEffect pvpSkillEffect

        ) {
            Long battleId = pvpSkillEffect.getBattleId();
            Long sourcePlayerHeroId = pvpSkillEffect.getSourcePlayerHeroId();
            Long targetPlayerHeroId = pvpSkillEffect.getTargetPlayerHeroId();
            PlayerHeroAttribute sourceAttribute = heroAttributeService.get(battleId, sourcePlayerHeroId);
            PlayerHeroAttribute targetAttribute = heroAttributeService.get(battleId, targetPlayerHeroId);
            Long coreSkillEffectTypeId = pvpSkillEffect.getCoreSkillEffectTypeId();
            String fieldName = pvpSkillEffect.getSkillEffectLayer().getName();
            Double value = pvpSkillEffect.getBaseEffectValueInfo().getBaseValue();

            double v = coreCombatFormulaService.physicsDotHurt(
                    //            long 进攻方兵力,
                    sourceAttribute.getCurrentForce(),
                    //             double 攻击方攻击,
                    sourceAttribute.getAtt(),
                    //             double 攻击方物理穿透,
                    sourceAttribute.getIgPhysicalDefense(),
                    //             double 攻击方战法加成,
                    value,
                    //             double 攻击方增减伤,
                    sourceAttribute.obtainStrategyAttackIncrease() - targetAttribute.obtainStrategyAttackDecrease(),
                    //             double 防守方防御
                    targetAttribute.getDef()
            );
            targetAttribute.attributeUpdate(
                    fieldName,
                    v,
                    0,
                    1,
                    coreSkillEffectTypeId
            );
            sourceAttribute.attributeUpdate(
                    fieldName,
                    v,
                    1,
                    1,
                    coreSkillEffectTypeId
            );

            heroAttributeService.saveCache(sourceAttribute);
            heroAttributeService.saveCache(targetAttribute);
        }

        public void strategyApply(
                PvpSkillEffect pvpSkillEffect
        ) {
            Long battleId = pvpSkillEffect.getBattleId();
            Long sourcePlayerHeroId = pvpSkillEffect.getSourcePlayerHeroId();
            Long targetPlayerHeroId = pvpSkillEffect.getTargetPlayerHeroId();
            PlayerHeroAttribute sourceAttribute = heroAttributeService.get(battleId, sourcePlayerHeroId);
            PlayerHeroAttribute targetAttribute = heroAttributeService.get(battleId, targetPlayerHeroId);
            Long coreSkillEffectTypeId = pvpSkillEffect.getCoreSkillEffectTypeId();
            String fieldName = pvpSkillEffect.getSkillEffectLayer().getName();
            Integer isMagic = pvpSkillEffect.getIsMagic();
            double value = pvpSkillEffect.getMagicInfluence()/100.0;
            double v = coreCombatFormulaService.strategyDotHurt(
                    //            long 进攻方兵力,
                    sourceAttribute.getCurrentForce(),
                    //             double 攻击方策略,
                    sourceAttribute.getMagic(),
                    //             double 攻击方策略穿透,
                    sourceAttribute.getIgStrategicDefense(),
                    //             double 攻击方战法基础伤害率,
                    1,
                    //             double 攻击方战法伤害率成长,
                    value,
                    //             int 是否受策略影响,
                    isMagic,
                    //             double 攻击方增减伤,
                    sourceAttribute.obtainStrategyAttackIncrease() - targetAttribute.obtainStrategyAttackDecrease(),
                    //             double 防守方策略
                    targetAttribute.getMagic()
            );
            targetAttribute.attributeUpdate(
                    fieldName,
                    v,
                    0,
                    1,
                    coreSkillEffectTypeId
            );
            sourceAttribute.attributeUpdate(
                    fieldName,
                    v,
                    1,
                    1,
                    coreSkillEffectTypeId
            );
            heroAttributeService.saveCache(sourceAttribute);
            heroAttributeService.saveCache(targetAttribute);

        }
    }

    // 28	溃逃 dot伤害，每回合行动开始受到一次物理伤害
    @Component
    public static class Dot28 extends BaseDotStrategy {
        @Override
        public PvpSkillEffect applyEffect(PvpSkillEffect pvpSkillEffect) {
            apply(pvpSkillEffect);
            return pvpSkillEffect;
        }

        public void apply(
                PvpSkillEffect pvpSkillEffect
        ) {
            physicsApply(pvpSkillEffect);
        }
    }

    // 29	燃烧 dot伤害，每回合行动开始受到一次策略伤害
    @Component
    public static class Dot29 extends BaseDotStrategy {
        @Override
        public PvpSkillEffect applyEffect(PvpSkillEffect pvpSkillEffect) {
            return super.applyEffect(pvpSkillEffect);
        }

        public void apply(
                PvpSkillEffect pvpSkillEffect
        ) {
            strategyApply(pvpSkillEffect);
        }
    }

    // 30	妖术 dot伤害，每回合行动开始受到一次策略伤害
    @Component
    public static class Dot30 extends BaseDotStrategy {
        @Override
        public PvpSkillEffect applyEffect(PvpSkillEffect pvpSkillEffect) {
            return super.applyEffect(pvpSkillEffect);
        }

        public void apply(
                PvpSkillEffect pvpSkillEffect
        ) {
            strategyApply(pvpSkillEffect);
        }
    }

    // 31	恐慌 dot伤害，每回合行动开始受到一次策略伤害
    @Component
    public static class Dot31 extends BaseDotStrategy {
        @Override
        public PvpSkillEffect applyEffect(PvpSkillEffect pvpSkillEffect) {
            return super.applyEffect(pvpSkillEffect);
        }

        public void apply(
                PvpSkillEffect pvpSkillEffect
        ) {
            strategyApply(pvpSkillEffect);
        }
    }
}